/*
 * @Author: zhengzhuang
 * @Date: 2020-08-05 14:22:15
 * @LastEditors: zhengzhuang
 * @LastEditTime: 2020-08-28 11:10:19
 * @Description: In User Settings Edit
 * @FilePath: /C20Driver_1.0.0/lib/utils/MyDialog.dart
 */
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:C20Driver/widget/progress_dialog.dart';
import 'package:C20Driver/widget/spinkit.dart';

class MyDialog {
  static void confirm(
      String title, String describe, context, Function callback) {
    showDialog(
        context: context,
        barrierDismissible: false, //这里设置蒙版是否可以穿透
        builder: (BuildContext context) {
          var width = MediaQuery.of(context).size.width; //获取屏幕的宽度
          return AlertDialog(
            contentPadding: EdgeInsets.all(0), //设置弹出框的内边距
            content: SingleChildScrollView(
              child: Container(
                child: Column(
                  children: <Widget>[
                    Container(
                      child: Text(
                        '$title',
                        style: TextStyle(
                            fontSize: 20, fontWeight: FontWeight.w500),
                      ),
                      margin: EdgeInsets.only(top: 20, bottom: 10),
                    ),
                    Container(
                      child: Text(
                        '$describe',
                        style: TextStyle(fontSize: 14, color: Colors.black38),
                      ),
                      margin: EdgeInsets.only(bottom: 10),
                    ),
                    Container(
                      child: Row(
                        children: <Widget>[
                          GestureDetector(
                            child: Container(
                              child: Text(
                                '取消',
                                style: TextStyle(
                                    fontSize: 16, color: Colors.black87),
                              ),
                              height: 50,
                              width: (width / 2) - 40,
                              decoration: BoxDecoration(
                                  color: Colors.white,
                                  border: Border(
                                      right: BorderSide(
                                          width: 1,
                                          color: Color.fromRGBO(
                                              223, 223, 223, 1)))),
                              alignment: Alignment.center,
                            ),
                            onTap: () {
                              Navigator.of(context).pop();
                            },
                          ),
                          GestureDetector(
                            child: Container(
                              child: Text(
                                '确定',
                                style: TextStyle(
                                    fontSize: 16,
                                    color: Color.fromRGBO(162, 204, 76, 1)),
                              ),
                              height: 50,
                              width: (width / 2) - 40,
                              decoration: BoxDecoration(
                                color: Colors.white,
                              ),
                              alignment: Alignment.center,
                            ),
                            onTap: () {
                              Navigator.of(context).pop();
                              //点击确定的时候，回调
                              callback();
                            },
                          )
                        ],
                      ),
                      decoration: BoxDecoration(
                          border: Border(
                              top: BorderSide(
                                  width: 1,
                                  color: Color.fromRGBO(223, 223, 223, 1)))),
                    )
                  ],
                ),
              ),
            ),
          );
        });
  }

  /// 加载中弹框
  static void loadDialog({BuildContext context}) {
    showDialog(
        context: context,
        barrierDismissible: true, //这里设置蒙版是否可以穿透
        builder: (BuildContext context) {
          var width = MediaQuery.of(context).size.width; //获取屏幕的宽度
          return Scaffold(
            backgroundColor: Color.fromARGB(50, 0, 0, 0),
            body: Container(
              alignment: Alignment.center,
              width: ScreenUtil().setWidth(750.0),
              child: SpinKitWave(
                color: Colors.black,
                size: 50.0,
              ),
            ),
          );
        });
  }
}
